# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ocaml-labltk
_pkgname=labltk
pkgver=8.06.12
pkgrel=2
_ocamlver=4.14
pkgdesc="Tcl/Tk interface for OCaml"
url="https://garrigue.github.io/labltk/"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.0-or-later WITH OCaml-LGPL-linking-exception"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	ocaml=~$_ocamlver
	ocaml-compiler-libs=~$_ocamlver
	tk-dev
	"
options="!check"  # no tests provided
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/garrigue/labltk/archive/refs/tags/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

build() {
	./configure --tk-no-x11
	make -j1 all
	make -j1 opt
}

package() {
	local libdir="$pkgdir/usr/lib/ocaml"

	mkdir -p "$libdir"/$_pkgname \
		"$libdir"/stublibs \
		"$pkgdir"/usr/bin

	export RANLIB=ranlib
	make install \
		BINDIR="$pkgdir/usr/bin" \
		INSTALLDIR="$pkgdir/usr/lib/ocaml/$_pkgname" \
		STUBLIBDIR="$pkgdir/usr/lib/ocaml/stublibs"

	# The *.o files are not installed by the Makefile.
	# AIUI that prevents linking with native code programs.
	install -m 0644 camltk/*.o "$libdir"/$_pkgname/
}

dev() {
	local sitelib="usr/lib/ocaml/$_pkgname"
	default_dev

	mkdir -p "$subpkgdir"/usr
	mv "$pkgdir"/usr/bin "$subpkgdir"/usr/

	cd "$pkgdir"/$sitelib
	mkdir -p "$subpkgdir"/$sitelib
	mv ./*.mli "$subpkgdir"/$sitelib/
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
e1564ab2d8922276bd8ad586b37308d60ca2dd563bac3cdd992d8a6ba4de26e5499350a62a1d4cb2bbb9a5b7aff609b5187aad5fba118eb55d1b4c8355d2979a  ocaml-labltk-8.06.12.tar.gz
"
